home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
drdobbs
/
1991
/
10
/
smalltlk.asc
< prev
next >
Wrap
Text File
|
1991-09-10
|
2KB
|
88 lines
_SMALLTALK AND EMBEDDED SYSTEMS_
by John Duimovich and Mike Milinkovich
Example 1
(a)
checkSum
"Answer a twos complement checksum of the receiver."
<primitive: checkSum>
^ self primitiveFailed
(b)
#include "userprim.h"
DEFINE_USER_PRIMITIVE( checkSum )
{
char *buffer;
unsigned int size;
unsigned short chkSum;
char *V_objectByteAddress();
buffer = V_objectByteAddress(PARAM(1));
size = V_objectSize (PARAM (1));
for (i=0;i<size;i++) {
chkSum += *buffer++;
}
SUCCEED (TO_SmallInteger(chkSum));
}
Examplσ 2
(a)
while {1) {
wait_for_data();
if (enough_data) V_interruptVM (20);
}
(b)
Process
configureInterrupt: 20
withMessage:
(DirectedMessage
selector: #enoughDataHasArrived
arguments: #()
receiver: dataHandler).
(c)
enoughDataHasArrived
"Inform the process waiting for the data that the
data has arrived."
dataFullSemaphore signal
(d)
[[true] whileTrue: [
dataFullSemaphore wait.
self processDataBuffer]] forkAt: 2
Examplσ 3
DEFINE_USER_PRIMITIVE(semaphoreSignal)
{
int semId;
IF ISNOT_SmallInteger (PARAM (1)) THEN FAIL; ENDIF
semId = TO_long (PARAM (1));
semGive (semId);
SUCCEED (SELF);
}